package com.emns.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.emns.pojo.Test;
import com.emns.service.TestService;


@Controller

@RequestMapping(value="/test")
public class EmnsTestController {
	
	@Autowired
	TestService ts;
	
	//查找所有测试数据
	@RequestMapping(value="")
	public String find(Model model,HttpServletRequest request){
		List<Test> testArr = ts.queryAll();
		model.addAttribute("info", testArr);;
		model.addAttribute("errCode", "0");
		model.addAttribute("errMsg", "");
		return "/test";
	}
	
	//添加测试数据
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public String add(Model model,Test test){
		ts.insert(test);
		return "redirect:/test";
	}
	
	
	//更新测试数据
	@RequestMapping(value="/update",method=RequestMethod.POST)
	public String update(Model model,Test test){
		ts.update(test);
		return "redirect:/test";
	}
	
	//删除测试数据
	@RequestMapping(value="/delete/{id}")
	public String delete(Model model,@PathVariable int id){
		ts.delete(id);
		return "redirect:/test";
	}
	
}
